import { fileURLToPath, URL } from 'node:url'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// https://vitejs.dev/config/
export default defineConfig({
  esbuild: {
    // drop: ['console', 'debugger'] // 删除 所有的console 和 debugger
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler', // 修改api调用方式
      },
    },
  },

  server: {
    https: false,
    host: true,
    port: 3007,
    open: false,
    cors: true,
    strictPort: false
  },
  plugins: [
    vue(),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      // 指定symbolId格式
      symbolId: 'icon-[name]'
    }),
    AutoImport({
      imports: [
        // 需要自动导入的插件，自定义导入的API
        'vue',
        'vue-router',
        'pinia'
      ],
      resolvers: [VantResolver()]
    }),
    Components({
      resolvers: [VantResolver()]
    })
  ],
  base: './',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
  // build: {
  //   rollupOptions: {
  //     output: {
  //       chunkFileNames: `static/js/[name].[hash]${Timestamp}.js`,
  //       entryFileNames: `static/js/[name].[hash]${Timestamp}.js`,
  //       assetFileNames: `static/[ext]/[name].[hash]${Timestamp}.[ext]`
  //     }
  //   }
  // }
})
